/**
 * @param {number[]} arr
 * @param {number} k
 * @return {number}
 */
 var kIncreasing = function(arr, k) {
  //  k <= i <= n-1
  // 使arr[i-k] <= arr[i]
  // index left <= right 
  const n = arr.length
  const left = {}, right = {}
  for(let i = k; i<n; i++){
    left[i] = i-k
    right[i-k] = i
  }
  let before = [...arr]
  let ans1 = 0
  for(let i = k; i<n; i++){
    let x = arr[left[i]], y = arr[right[i]]
    if(arr[i] >= x) continue
    arr[i] = x
    ans1++
  }
  arr = before
  let ans2 = 0
  for(let i = n-k-1; i>=0; i--){
    let y = arr[right[i]]
    if(arr[i] <= y) continue
    arr[i] = y
    ans2++
  }
  console.log(arr, ans1, ans2)
  return Math.min(ans1, ans2)
};